package cn.com.dycc.party_org.member.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.common.entity.Pb_Integral_LogCount;
import cn.com.dycc.party_org.member.entity.AllInfo;
import cn.com.dycc.party_org.member.entity.CountMember;
import cn.com.dycc.party_org.member.entity.Member;
import cn.com.dycc.party_org.member.entity.UserAndMember;
import cn.com.dycc.party_org.member.entity.UserChildAndMember;
import cn.com.dycc.party_org.member.param.FindMemberParam;
import cn.com.dycc.party_org.member.param.MemberParam;
import cn.com.dycc.party_org.member.service.MemberNotFoundException;
import cn.com.dycc.party_org.member.service.MemberService;
import cn.com.dycc.study_manage.integral.param.Pb_Integral_LogParam;
import cn.com.dycc.sys_manage.logsysmanagement.service.LogNotFoundException;
import cn.com.dycc.util.JsonObjectResult;

/**
 * 
 * Description: 党员信息控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月25日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/member")
public class MemberController extends BaseController{

	@Resource
	private MemberService memberService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addMember(MemberParam member,HttpServletRequest req){
		System.out.println(member);
		int n = memberService.addMember(member, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteMember(String user_id,HttpServletRequest req){
		int n = memberService.deleteMember(user_id, req);
		return new JsonObjectResult(n);
	}
	
	/*@RequestMapping("/deleteall.do")
	@ResponseBody
	public JsonObjectResult deleteAllMember(String user_ids[],HttpServletRequest req){
		int n = memberService.deleteAllMember(user_ids, req);
		return new JsonObjectResult(n);
	}*/
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateMember(MemberParam member,HttpServletRequest req){
		int n = memberService.updateMember(member, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findMember(String user_id,HttpServletRequest req){
		Member member = memberService.findMember(user_id, req);
		return new JsonObjectResult(member);
	}
	
	@RequestMapping("/findone.do")
	@ResponseBody
	public JsonObjectResult findMemberByUserId(String user_id,HttpServletRequest req){
		UserChildAndMember member = memberService.findMemberByUserId(user_id, req);
		return new JsonObjectResult(member);
	}
	
	@RequestMapping("/findall.do")
	@ResponseBody
	public JsonObjectResult findAllMember(FindMemberParam param,HttpServletRequest req){
		String count = memberService.findAllMemberCount(param,req);
		List<UserAndMember> list = memberService.findAllMember(param,req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult findAllMemberByParam(FindMemberParam param,HttpServletRequest req){
		String count = memberService.findAllMemberCountByParam(param,req);
		List<UserChildAndMember> list = memberService.findAllMemberByParam(param,req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/countmember.do")
	@ResponseBody
	public JsonObjectResult countMember(HttpServletRequest req)throws LogNotFoundException{
		CountMember cm = memberService.countMember(req);
		return new JsonObjectResult(cm);
	}
	
	@RequestMapping("/allinfo.do")
	@ResponseBody
	public JsonObjectResult allInfoCount(HttpServletRequest req)throws LogNotFoundException{
		AllInfo info = memberService.allInfoCount(req);
		return new JsonObjectResult(info);
	}
	
	@RequestMapping("/integral.do")
	@ResponseBody
	public JsonObjectResult integralCount(HttpServletRequest req,Pb_Integral_LogParam param)throws LogNotFoundException{
		List<Pb_Integral_LogCount> list = memberService.countMemberByIntegral(req, param);
		return new JsonObjectResult(list);
	}
	
	@ExceptionHandler(MemberNotFoundException.class)
	@ResponseBody
	public JsonObjectResult memberException(MemberNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(55,e);
	}
	

}
